package com.wave.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.wave.olap.OlapBean;
import com.wave.olap.OlapCriteria;
import com.wave.olap.OracleOlapCriteria;
import com.wave.olap.OracleOlapService;


@Controller
public class OlapController {
	
	@Autowired OracleOlapService olapService;

	@RequestMapping("/olap.do")
	public ModelMap olapHandler(@RequestParam("product") String product) {
		if (product == null || product.equals(""))
			product = "PRIMARY::TOTAL_PRODUCT::1";
		OlapCriteria<String> oc = new OracleOlapCriteria("SALES");
		oc.addCriteria("CHANNEL", new String[] { "PRIMARY::TOTAL_CHANNEL::1", "PRIMARY::CHANNEL::4" });
		oc.addCriteria("CUSTOMER", new String[] { "SHIPMENTS::TOTAL_CUSTOMER::1", "SHIPMENTS::REGION::8", "SHIPMENTS::REGION::9", "SHIPMENTS::REGION::10" });
		oc.addCriteria("TIME", new String[] { "CALENDAR_YEAR::QUARTER::10", "CALENDAR_YEAR::MONTH::34", "CALENDAR_YEAR::MONTH::35", "CALENDAR_YEAR::MONTH::36","CALENDAR_YEAR::MONTH::37", "CALENDAR_YEAR::MONTH::38", "CALENDAR_YEAR::MONTH::39"});
		oc.addCriteria("PRODUCT", new String[] { product });
		oc.addOrder("CHANNEL").addOrder("CUSTOMER").addOrder("TIME");
		return new ModelMap("olap", (OlapBean<String,?>)olapService.query(oc));
	}	
	
	@RequestMapping("/olapdropdown.do")
	public ModelMap dropdownHandler() {
		return new ModelMap("dimension", olapService.getDimensionDataElements("PRODUCT"));
	}

}
